﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SimpleMVC.Service;
using SimpleMVC.Models;
using SimpleMVC.Filters;


namespace SimpleMVC.Controllers
{
    public class HomeController : Controller
    {
        private IIocTest iocTestInsatnce;
        public HomeController(IIocTest iocTest)
        {
            iocTestInsatnce = iocTest;
        }
        public ActionResult Index()
        {
            ViewBag.iocSays = iocTestInsatnce.Say();
            var r = RouteData.Route.ToString();
            return View();
        }
        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";

            return View();
        }
        
        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }
        public ActionResult TError()
        {
            throw new AggregateException("test error");
        }

        public ActionResult ShowID(int? userid)
        {
            ViewBag.userid = userid;
            return View();
        }
        public ActionResult ShowTeacher(Teacher teacher)
        {
            if (ModelState.IsValid)
            {
                return View(teacher);
            }
            else
            {
                return Redirect("Index");
            }
        }

        [HttpGet, PRGModelState]
        public ActionResult AddStudent()
        {
            return View();
        }

        [PRGModelState]
        public ActionResult AddStudent(Student student)
        {
            if (ModelState.IsValid)
            {
                return Redirect("Index");
            }
            else
            {
                return Redirect("AddStudent");
            }
        }
    }
}